//
//  ZMyOrderListOrderInfoCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/14.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyOrderListOrderInfoCell.h"

@interface ZMyOrderListOrderInfoCell ()
@property (nonatomic, strong) UIImageView *ivShop;//产品图片
@property (nonatomic, strong) UILabel *lblName;//产品名称
@property (nonatomic, strong) UILabel *lblType;//产品型号
@property (nonatomic, strong) UILabel *lblNumber;//产品数量
@property (nonatomic, strong) UIButton *btnChange;//修改数量
@property (nonatomic, strong) UIButton *btnCancel;//取消预订
@property (nonatomic, strong) UILabel *lblCancel;//已取消提示
@property (nonatomic, strong) UILabel *lblPrice;//价格(省级经销商)
@property (nonatomic, strong)UILabel *lblNoticeNumber;//数量 文字
@end

@implementation ZMyOrderListOrderInfoCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    
    _ivShop = [[UIImageView alloc] initWithFrame:CGRectMake(16, 13, 60, 60)];
    _ivShop.backgroundColor = kColorWithHex(0xf2f2f2);
    _ivShop.contentMode = UIViewContentModeScaleToFill;
    [self.contentView addSubview:_ivShop];
    
    _lblName = [UILabel new];
    _lblName.font = [UIFont systemFontOfSize:14];
    _lblName.textColor = kColorWithHex(0x333333);
    _lblName.numberOfLines = 2;
    _lblName.preferredMaxLayoutWidth = kScreen_Width - 109;
    [self.contentView addSubview:_lblName];
    [_lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.ivShop.mas_trailing).offset(13);
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-21);
    }];
    
    UILabel *lblNoticeType = [UILabel new];
    lblNoticeType.text = @"型号";
    lblNoticeType.font = [UIFont systemFontOfSize:14];
    lblNoticeType.textColor = kColorWithHex(0x666666);
    [self.contentView addSubview:lblNoticeType];
    [lblNoticeType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblName.mas_leading);
        make.top.equalTo(self.lblName.mas_bottom).offset(7);
        make.size.mas_equalTo(CGSizeMake(30, 20));
    }];
    
    _lblType = [UILabel new];
    _lblType.font = [UIFont systemFontOfSize:14];
    _lblType.textColor = kColorWithHex(0x272727);
    [self.contentView addSubview:_lblType];
    [_lblType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lblNoticeType.mas_centerY);
        make.leading.equalTo(lblNoticeType.mas_trailing).offset(12);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-21);
        make.height.mas_equalTo(20);
    }];
    
    _lblNoticeNumber = [UILabel new];
    _lblNoticeNumber.text = @"数量";
    _lblNoticeNumber.font = [UIFont systemFontOfSize:14];
    _lblNoticeNumber.textColor = kColorWithHex(0x666666);
    [self.contentView addSubview:_lblNoticeNumber];
    [_lblNoticeNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(lblNoticeType.mas_leading);
        make.top.equalTo(lblNoticeType.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(30, 20));
    }];

    
    _lblNumber = [UILabel new];
    _lblNumber.font = [UIFont systemFontOfSize:14];
    _lblNumber.textColor = kColorWithHex(0x4a4a4a);
    [self.contentView addSubview:_lblNumber];
    [_lblNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_lblNoticeNumber.mas_centerY);
        make.leading.equalTo(_lblNoticeNumber.mas_trailing).offset(12);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-21);
        make.height.mas_equalTo(20);
    }];
    
    _lblPrice = [UILabel new];
    _lblPrice.font = [UIFont boldSystemFontOfSize:16];
    _lblPrice.textColor = kColorWithHex(0x70be68);
    [self.contentView addSubview:_lblPrice];
    [_lblPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_lblNoticeNumber.mas_centerY);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-16);
        make.height.mas_equalTo(22);
    }];
    
    
    _btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btnCancel setImage:imgname(@"order_cancel_icon") forState:UIControlStateNormal];
    [_btnCancel addTarget:self action:@selector(btnCancelClickAction:) forControlEvents:UIControlEventTouchUpInside];
    _btnCancel.hidden = YES;
    [self.contentView addSubview:_btnCancel];
    [_btnCancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-11);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-16);
        make.size.mas_equalTo(CGSizeMake(69, 26));
    }];
    
    _btnChange = [UIButton buttonWithType:UIButtonTypeCustom];
    [_btnChange setImage:imgname(@"order_change_number_icon") forState:UIControlStateNormal];
    [_btnChange addTarget:self action:@selector(btnChangeClickAction:) forControlEvents:UIControlEventTouchUpInside];
    _btnChange.hidden = YES;
    [self.contentView addSubview:_btnChange];
    [_btnChange mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-11);
        make.trailing.equalTo(self.btnCancel.mas_leading).offset(-8);
        make.size.mas_equalTo(CGSizeMake(69, 26));
    }];
    
    _lblCancel = [UILabel new];
    _lblCancel.text = @"已取消";
    _lblCancel.font = [UIFont systemFontOfSize:14];
    _lblCancel.textColor = kColorWithHex(0xd84b4a);
    _lblCancel.hidden = YES;
    [self.contentView addSubview:_lblCancel];
    [_lblCancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-11);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-29);
        make.height.mas_equalTo(20);
    }];
    
    UIView *viewLine = [UIView new];
    viewLine.backgroundColor = kColorWithHex(0xf2f2f2);
    [self.contentView addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.height.mas_equalTo(1);
    }];
    
}
#pragma mark - 数据更新
- (void)setPartModel:(BShopPartModel *)partModel{
    if (partModel) {
        _partModel = partModel;
        [HFTools imageViewUpdateWithUrl:partModel.image_url withImageView:_ivShop withPlaceholderImage:@""];
        _lblName.text = partModel.parts_name;
        _lblType.text = partModel.name;
        _lblNumber.text = partModel.count;
        if ([partModel.state isEqualToString:@"1"]) {
            _btnCancel.hidden = NO;
            _btnChange.hidden = NO;
            _lblCancel.hidden = YES;
        }else if([partModel.state isEqualToString:@"2"]){
            _btnCancel.hidden = YES;
            _btnChange.hidden = YES;
            _lblCancel.hidden = NO;
        }else if([partModel.state isEqualToString:@"3"]){
            //平台处理(不能修改状态和取消预订)
            _btnCancel.hidden = YES;
            _btnChange.hidden = YES;
            _lblCancel.hidden = YES;
        }
        if (AGENT_LEVEL == 1) {
            _lblPrice.text = [NSString stringWithFormat:@"￥%@/件",partModel.salePrice];
            
        }
        //市县级 数量相关的 全部隐藏不显示
        else
        {
            _lblNoticeNumber.hidden = YES;
            _lblNumber.hidden = YES;
            _btnChange.hidden = YES;
        }
    }
}
#pragma mark - 交互事件
- (void)btnCancelClickAction:(UIButton *)sender{
    if (self.partModel && self.delegate && [self.delegate respondsToSelector:@selector(orderListOrderInfoCellBtnCancelClick:)]) {
        [self.delegate orderListOrderInfoCellBtnCancelClick:self.indexPath];
    }
}
- (void)btnChangeClickAction:(UIButton *)sender{
    if (self.partModel && self.delegate && [self.delegate respondsToSelector:@selector(orderListOrderInfoCellBtnChangeClick:)]) {
        [self.delegate orderListOrderInfoCellBtnChangeClick:self.indexPath];
    }
}

+ (CGFloat)cellHeight{
    //市县级降低高度
    if (AGENT_LEVEL != 1)
    {
        return 151.0-20;
    }
    return 151.0;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
